package com.example.sprintbootarithmetic.DataStructure.recursion;

public class MiGongShortest {
    public static void main(String[] args) {
        int[][] num = new int[8][7];
        for (int i = 0; i < 8; i++) {
            num[i][0] = 1;
            num[i][6] = 1;
        }
        for (int j = 0; j < 7; j++) {
            num[0][j] = 1;
            num[7][j] = 1;
        }
        num[3][1] = 1;
        num[3][2] = 1;
        result(num, 1, 1, 6, 5);
        for (int i = 0; i < 8; i++) {
            for (int j = 0; j < 7; j++) {
                System.out.print(num[i][j] + "\t");
            }
            System.out.println();
        }
    }

    public static boolean result(int[][] map, int i, int j, int x, int y) {
        if (map[x][y] == 2) {
            return true;
        } else {
            if (map[i][j] == 0) {
                map[i][j] = 2;
                boolean flag = false;
                if (i > x && j < y) {//��Ŀ���Ķ��Ϸ���
                    if (result(map, i, j - 1, x, y) || result(map, i - 1, j, x, y)) {
                        return true;
                    }
                } else if (i < x && j < y) {//��Ŀ�����������
                    if (result(map, i + 1, j, x, y) || result(map, i, j + 1, x, y)) {
                        return true;
                    }
                } else if (i < x && j > y) {//��Ŀ�����������
                    if (result(map, i + 1, j, x, y) || result(map, i, j - 1, x, y)) {
                        return true;
                    }
                } else if (i > x && j > y) {//��Ŀ�궫������
                    if (result(map, i + 1, j, x, y) || result(map, i + 1, j, x, y)) {
                        return true;
                    }
                } else if (i == x && j > y) {//��Ŀ��Ķ���
                    if (result(map, i, j - 1, x, y)) {//������
                        return true;
                    }
                } else if (i == x && j < y) {//��Ŀ���������
                    if (result(map, i, j + 1, x, y)) {
                        return true;
                    }
                } else if (j == y && i > x) {//��Ŀ��ı���
                    if (result(map, i + 1, j, x, y)) { //������
                        return true;
                    }
                } else if (j == y && i < x) {//��Ŀ����Ϸ�
                    if (result(map, i - 1, j, x, y)) {
                        return true;
                    }
                }
                return flag;
            } else {
                return false;
            }
        }
    }
}
